package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCdemo2 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        System.out.println("加载驱动成功");
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root"
        );
        String sql="insert into lkp(id,username,password,nickname,age)"+
                "values(1,'lkp','123456','lkp',18)";
        Statement statement = connection.createStatement();
        int num = statement.executeUpdate(sql);
        if(num>0){
            System.out.println("插入成功");
        }else{
            System.out.println("插入失败");
        }
        connection.close();
        System.out.println("关闭连接");
    }
}
